#ifndef TLRSYNTAXHIGHLIGHTER_H
#define TLRSYNTAXHIGHLIGHTER_H

#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QRegularExpression>

enum TSyntaxFormat {
    syntaxFmtJson,         //JSON格式
    syntaxFmtCpp,          //CPP格式
};


class TLRSyntaxHighlighter : public QSyntaxHighlighter
{
    Q_OBJECT
public:
    TLRSyntaxHighlighter(QTextDocument *parent = nullptr);

    //设置语言格式
    void setSyntaxFormat(const TSyntaxFormat &nsyntaxfmt);

protected:
    void highlightBlock(const QString &text) override;

private:
    struct THighlightRule {
        QRegularExpression pattern;    //正则表达式
        QTextCharFormat textFormat;    //文本格式
    };
    //正则匹配规则
    QList<THighlightRule> m_highlightRules;
    //语言格式
    TSyntaxFormat m_syntaxFmt = TSyntaxFormat::syntaxFmtJson;

};

#endif // TLRSYNTAXHIGHLIGHTER_H
